<?xml version="1.0" encoding="utf-8" ?> 
<sqlMap namespace="News"
	xmlns="http://ibatis.apache.org/mapping" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<alias>
		<typeAlias alias="News" type="Domain.News" />
	</alias>

	<resultMaps>
		<resultMap id="FullResultMap" class="News">
			<result property="newsId" column="newsId" dbType="Int"/>
			<result property="newsSource" column="newsSource" dbType="NVarChar"/>
			<result property="newsAuthor" column="newsAuthor" dbType="NVarChar"/>
			<result property="newsTitle" column="newsTitle" dbType="NVarChar"/>
			<result property="newsSummary" column="newsSummary" dbType="NVarChar"/>
			<result property="newsContent" column="newsContent" dbType="NText"/>
			<result property="newsType" column="newsType" dbType="VarChar"/>
			<result property="newsHits" column="newsHits" dbType="Int"/>
			<result property="addTime" column="addTime" dbType="SmallDateTime"/>
		</resultMap>
	</resultMaps>
	
	<statements>

		<select id="GetCount" resultClass="System.Int32">
			SELECT count(*) FROM [dbo].[news]
		</select>
		
		<select id="GetCountByCondition" parameterClass="Hashtable" resultClass="System.Int32" extends="GetCount">
			WHERE $condition$
		</select>
		
		<select id="FindAll" resultClass="News">
			SELECT * 
			FROM [dbo].[news]
		</select>
		
		<select id="GetModel" parameterClass="News" resultClass="News" extends="FindAll">
			WHERE
				([news].[newsId] = #newsId,dbType=Int#)
		</select>

		<insert id="Insert" parameterClass="News">
			INSERT INTO [dbo].[news] (
				
				[newsSource] , 
				[newsAuthor] , 
				[newsTitle] , 
				[newsSummary] , 
				[newsContent] , 
				[newsType] , 
				[newsHits] , 
				[addTime]
			) VALUES (
				
				 #newsSource,dbType=NVarChar# , 
				 #newsAuthor,dbType=NVarChar# , 
				 #newsTitle,dbType=NVarChar# , 
				 #newsSummary,dbType=NVarChar# , 
				 #newsContent,dbType=NText# , 
				 #newsType,dbType=VarChar# , 
				 #newsHits,dbType=Int# , 
				 #addTime,dbType=SmallDateTime#
			)
		</insert>

		<update id="Update" parameterClass="News">
			UPDATE [dbo].[news] SET
				 [newsSource] = #newsSource,dbType=NVarChar#
				, [newsAuthor] = #newsAuthor,dbType=NVarChar#
				, [newsTitle] = #newsTitle,dbType=NVarChar#
				, [newsSummary] = #newsSummary,dbType=NVarChar#
				, [newsContent] = #newsContent,dbType=NText#
				, [newsType] = #newsType,dbType=VarChar#
				, [newsHits] = #newsHits,dbType=Int#
				, [addTime] = #addTime,dbType=SmallDateTime#
			WHERE
				([newsId] = #newsId,dbType=Int#)
		</update>

		<delete id="Delete" parameterClass="News">
			DELETE FROM [dbo].[news]
			WHERE
				([newsId] = #newsId,dbType=Int#)
		</delete>

		<select id="GetModelsByCondition" parameterClass="Hashtable" resultClass="News">
			SELECT $columnNames$ FROM [dbo].[news] where $condition$
		</select>
		
		<select id="GetModelsByConditionByPager" parameterClass="Hashtable" resultClass="News">
      declare @indextable table(rno int identity(1,1),nid int)
      insert into @indextable(nid) select [newsid] from [dbo].[news]
      where $condition$ order by $orderBy$

      select $columnNames$ from
      [dbo].[news] ,@indextable t
      <![CDATA[
			where t.nid= [news].newsid and t.rno>#startNo# and t.rno<=#endNo# 
      order by t.rno asc
			]]>
		</select>
		
	</statements>
</sqlMap>
